﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace FileSlurpeeConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            if (!ValidateArguments(args))
                return;

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("The configuration file you specified doesn't exist");
                return;
            }

            var deserializer = new XmlSerializer(typeof(FileSlurpeeCore.FileSlurper), "http://tempuri.org/SlurpeeSchema.xsd");
            var fileSlurpee = deserializer.Deserialize(File.OpenRead(args[0])) as FileSlurpeeCore.FileSlurper;

            if (fileSlurpee == null)
            {
                Console.WriteLine("The configuration file did not successfully parse into a File Slurpee class. Check your configuration and try again");
                return;
            }

            fileSlurpee.SlurpFiles();

            //var finder = new FileSlurpeeCore.FileSlurper();
            //finder.DestinationPath = "";
            //finder.FilePatternList = new List<string> { "*.*", "blah", "blah2" };
            //finder.MaxThreads = 4;
            //finder.Recursive = false;
            //finder.SearchPaths = new List<string> { "*", "blah", "blah2" };

            //var serializer = new XmlSerializer(finder.GetType());
            //var writer = new StreamWriter("FinderXml.xml");
            //serializer.Serialize(writer, finder);
        }

        private static bool ValidateArguments(string[] args)
        {
            if (args.Length < 1 || string.IsNullOrWhiteSpace(args[0]))
            {
                Usage();
                return false;
            }

            return true;
        }

        private static void Usage()
        {
            Console.WriteLine("Usage:");
            Console.WriteLine("FileSlurpeeConsole <ConfigFileName>");
        }
    }
}
